package com.xudow.app.newui.zutils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.activeshare.edu.ucenter.models.base.UserProfile;
import com.activeshare.edu.ucenter.models.user.UserSecret;

/**
 * 作者：zhouXJ on 2016/4/8 11:32
 * 保存选中按钮状态
 */
public class ZPreferenceUtils {

    /**
     * 通过昵称找到我选中按钮
     */
    public static final String PREF_NICKNAME = "pref_nickname";

    /**
     * 通过真实姓名找到我选中按钮
     */
    public static final String PREF_TRUE_NAME = "pref_true_name";

    /**
     * 通过账号找到选中按钮
     */
    public static final String PREF_ACCOUNT_NUM = "pref_account_num";

    /**
     * 评论选中按钮
     */
    public static final String PREF_COMMENT = "pref_comment";

    /**
     * 赞选中按钮
     */
    public static final String PREF_PRAISE = "pref_praise";

    /**
     * 粉丝选中按钮
     */
    public static final String PREF_FANS = "pref_fans";

    /**
     * 系统通知选中按钮
     */
    public static final String PREF_SYSTEM = "pref_system";

    /**
     * 系统课表选中按钮
     */
    public static final String PREF_SCHEDULE = "pref_schedule";

    /**
     * 保存按钮状态
     *
     * @param context
     * @param key
     * @param b
     */
    public static void saveSwitchBtnState(Context context, String key, boolean b) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(key, b);
        editor.commit();

    }
    public static void saveUserSecret(Context context,UserSecret data){
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(PREF_NICKNAME,getState(data.getNickname()));
        editor.putBoolean(PREF_TRUE_NAME,getState(data.getRealname()));
        editor.putBoolean(PREF_ACCOUNT_NUM,getState(data.getUsercode()));
        editor.putBoolean(PREF_COMMENT,getState(data.getBecommented()));
        editor.putBoolean(PREF_PRAISE,getState(data.getBeliked()));
        editor.putBoolean(PREF_FANS,getState(data.getBeattentioned()));
        editor.putBoolean(PREF_SYSTEM,getState(data.getSystemnotice()));
        editor.putBoolean(PREF_SCHEDULE,getState(data.getCourses()));
        editor.commit();
    }

    private static boolean getState(Integer n){
        if (n==1) {
            return true;
        }else {
            return false;
        }
    }
    /**
     * 获取按钮状态  默认返回true
     *
     * @param context
     * @param key
     * @return
     */
    public static boolean getSwitchBtnState(Context context, String key) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getBoolean(key, true);

    }

}
